<template>
    <h1>添加理财项目信息</h1>

    <table>
        <tr>
            <td>项目名称</td>
            <td>
                <input type="text" v-model="Borrow.B_Name" >
            </td>
        </tr>

        <tr>
            <td>年收益</td>
            <td>
                <input type="text" v-model="Borrow.B_YearMoney" >
            </td>
        </tr>

        <tr>
            <td>最低金额</td>
            <td>
                <input type="text" v-model="Borrow.B_MinMoney" >
            </td>
        </tr>

        <tr>
            <td>风险等级</td>
            <td>
                <input type="text" v-model="Borrow.B_Fxbj" >
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="提交" @click="AddBorrow">
            </td>
        </tr>

    </table>


</template>

<script setup lang="ts">

import { ref } from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'

const router = useRouter()

const Borrow = ref({
    B_Name:'',
    B_YearMoney:'',
    B_MinMoney:'',
    B_Fxbj:''
})

const AddBorrow = () => {
    axios({
        url:'http://localhost:52659/api/Borrow/AddBorrow',
        method:'post',
        data:{
            B_Name:Borrow.value.B_Name,
            B_YearMoney:Borrow.value.B_YearMoney,
            B_MinMoney:Borrow.value.B_MinMoney,
            B_Fxbj:Borrow.value.B_Fxbj
        }
    })
    .then(res => {
        if(res.data>0){
            alert('添加成功')
            router.push('/ShowBorrow')
        }
        else if(res.data==-1){
            alert('理财项目名称已存在')
        }
        else{
            alert('添加失败')
        }
    })
    .catch(err => {
        console.log(err)
    })
}


</script>
